package com.gxa.utils;

/**
 * Created by shelei on 2022/1/18 10:44
 */
public class ResultUtils {


    /**
     * 构建成功带分页
     * @param count
     * @param data
     * @return
     */
    public static Result buildSuccess(Long count, Object data){
        Result result=new Result();
        result.setCode(MessageCode.REQUEST_SUCCESS.getCode());
        result.setMsg(MessageCode.REQUEST_SUCCESS.getMsg());
        result.setData(data);
        result.setCount(count);
        return result;
    }


    /**
     * 构建单个结果的成功
     * @param data
     * @return
     */
    public static Result buildSuccess(Object data){
        return buildSuccess(null,data);
    }


    /**
     * 不带数据返回的请求成功
     * @return
     */
    public static Result buildSuccess(){
        return buildSuccess(null);
    }


    /**
     * 构建失败信息
     * @param code
     * @param msg
     * @return
     */
    public static Result buildFail(Integer code, String msg){
        Result result=new Result();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }



    /**
     * 构建失败信息
     * @return
     */
    public static Result buildFail(MessageCode messageCode){
        Result result=new Result();
        result.setCode(messageCode.getCode());
        result.setMsg(messageCode.getMsg());
        return result;
    }


}
